var fenlei = document.getElementsByClassName('fenlei');
var nav_none = document.getElementsByClassName('nav-none');
var shuigt = document.getElementsByClassName('shuigt');
var navtitle = document.getElementById('nav-title')
var xianshi = document.getElementsByClassName('xianshi')[0];



// 商品分类 显示隐藏
xianshi.style.display = 'none'

navtitle.onmouseover = function () {
    xianshi.style.display = 'block'
}
navtitle.onmouseout = function () {
    xianshi.style.display = 'none'
}
xianshi.onmouseover = function () {
    xianshi.style.display = 'block'
}
xianshi.onmouseout = function () {
    xianshi.style.display = 'none'
}

// 全部商品分类 显示隐藏
nav_none[0].style.display = 'none'

for (let i = 0; i < fenlei.length; i++) {
    shuigt[i].style.backgroundPosition = -i * 24 + 'px' + ' 0px'
    if (i === 0)
    {
        fenlei[i].style.top = '36px'
        
    } else {
        fenlei[i].style.top = i*43+36+'px'    
    }

    // 注册水果事件
    fenlei[i].onmouseover = function (e) {
        this.display = 'block'
        fenlei[i].classList.add('mafan')
        for (let j = 0; j < nav_none.length; j++) {
            nav_none[j].style.display = 'none'
        }
        nav_none[i].style.display = 'block'
    }
    fenlei[i].onmouseout = function () {
        nav_none[i].style.display = 'none'
        fenlei[i].classList.remove('mafan')
        return

    }
    nav_none[i].onmouseover = function () {
        this.style.display = 'block'
        fenlei[i].classList.add('mafan')

    }
    nav_none[i].onmouseout = function () {
        this.style.display = 'none'
        fenlei[i].classList.remove('mafan')
        return
    }
}
var gudingtop = document.getElementById('gudingtop');

var guding = document.getElementById('guding')
guding.onmouseover = function () {
    guding.style.backgroundPosition = '-56px -46px'
}
guding.onmouseout = function () {
    guding.style.backgroundPosition = '0 -46px'
}
if (document.documentElement.scrollTop > 290) {
    gudingtop.style.display = 'block'
    guding.style.bottom = '60px'
    
} else {
    gudingtop.style.display = 'none'
    guding.style.bottom = '20px'
}
window.onscroll = function () {
    if (document.documentElement.scrollTop > 290) {
        gudingtop.style.display = 'block'
        guding.style.bottom = '60px'
        
    } else {
        gudingtop.style.display = 'none'
        guding.style.bottom = '20px'
    }
}

gudingtop.onclick = function(e){
    e.preventDefault();

    let a = document.documentElement.scrollTop;
    let b = 0;
    let s = b - a;
    let sudu = parseInt(s / 600 * 17);
    var timer =null
    timer= setInterval(function () {
            a += sudu;
            if (a < b) {
                clearInterval(timer);
            }
        document.documentElement.scrollTop = a
    },17)
}